﻿CREATE PROCEDURE [acms].[UserPostUploadFile_Put]
	@UserPostUploadId int,
	@Key varchar(20),
	@FileId int,
	@FileTypeOut int output,
	@NameOut varchar(50) output,
	@WidthOut int output,
	@HeightOut int output
AS
	if exists (select null from UserPostUploadFile_View with (nolock) where UserPostUploadId = @UserPostUploadId and [Key] = @Key) begin
		update UserPostUploadFiles
		set FileId = @FileId
		where UserPostUploadId = @UserPostUploadId and [Key] = @Key
	end
	else begin
		insert into UserPostUploadFiles
			(UserPostUploadId, [Key], FileId)
		values
			(@UserPostUploadId, @Key, @FileId)
	end
	
	select @FileTypeOut = FileType, @NameOut = Name, @WidthOut = Width, @HeightOut = Height
	from UserPostUploadFile_View with (nolock) where UserPostUploadId = @UserPostUploadId and FileId = @FileId
RETURN 0